package com.itheima02.day07;

import java.util.Scanner;

/**
 * @author 刘全
 * @date 2021/7/23
 */
public class ExceptionDemo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Student stu = new Student();
        System.out.println("请输入您的姓名:");
        String name = sc.next();
        while (true) {
            try {
                System.out.println("请输入您的年龄:");
                String ageStr = sc.next();
                int age = Integer.parseInt(ageStr);
                stu.setAge(age);
                stu.setName(name);
                System.out.println("录入成功");
                System.out.println(stu);
                break;
            } catch (NumberFormatException e) {
                System.out.println("请输入一个整数!");
                continue;
            } catch (AgeOutOfBoundsException e) {
                System.out.println(e.toString());
                continue;
            }
        }
    }

}
